package com.hpq.chat.service.srategy.msg;

import com.hpq.chat.dao.MessageDAO;
import com.hpq.chat.domain.enums.MessageTypeEnum;
import com.hpq.chat.domain.model.Message;
import com.hpq.chat.domain.model.msg.EmojisMsgDTO;
import com.hpq.chat.domain.model.msg.MessageExtra;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class EmojisMsgHandler extends AbstractMsgHandler<EmojisMsgDTO> {

    @Autowired
    private MessageDAO messageDao;
    @Override
    MessageTypeEnum getMsgTypeEnum() {
        return MessageTypeEnum.EMOJI;
    }

    @Override
    protected void saveMsg(Message message, EmojisMsgDTO body) {
        MessageExtra extra = Optional.ofNullable(message.getExtra()).orElse(new MessageExtra());
        Message msg = new Message();
        msg.setId(message.getId());
        msg.setExtra(extra);
        extra.setEmojisMsgDTO(body);
        messageDao.updateById(msg);
    }

    @Override
    public Object showMsg(Message msg) {
        return msg.getExtra().getEmojisMsgDTO();
    }

    @Override
    public Object showReplyMsg(Message msg) {
        return "表情";
    }

    @Override
    public String showContactMsg(Message msg) {
        return "[表情]";
    }
}
